﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using App.Codes;
using Newtonsoft.Json;

namespace App.Controllers
{
    public class RanklistController : Controller
    {
        //
        // GET: /Ranklist/

        public ActionResult Index()
        {
            return View();
        }

        public string GetChatInfo(string fromtime, string totime, string type, string rank)
        {
            DateTime dtfromtime=new DateTime(2000,1,1);
            DateTime dttotime = DateTime.Now;

            if (string.IsNullOrEmpty(fromtime) && string.IsNullOrEmpty(totime))
            {
                dtfromtime = Convert.ToDateTime(DateTime.Now.ToShortDateString()).AddDays(-7);
            }

            if (!string.IsNullOrEmpty(fromtime))
            {
                  dtfromtime=DateTime.ParseExact(fromtime, "dd/MM/yyyy", null);
                 
                
            }
            if (!string.IsNullOrEmpty(totime))
            {
                dttotime = DateTime.ParseExact(totime, "dd/MM/yyyy", null).AddDays(1);
                
            }

            if (type == "窗口")
            {
                SqlParameter[] prms = new SqlParameter[]
                {
                    new SqlParameter("@fromtime ", SqlDbType.DateTime),
                    new SqlParameter("@totime ", SqlDbType.DateTime),
                    new SqlParameter("@selectcount ", SqlDbType.Int),

                };
                prms[0].Value = dtfromtime;
                prms[1].Value = dttotime;
                prms[2].Value = rank;
                SqlConnection con = SqlHelper.GetConnection();
                DataSet ds = SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "sp_departmentappraise", prms);
                DataTable dt = ds.Tables[0];
                return JsonConvert.SerializeObject(dt);
            }
            else
            {
                SqlParameter[] prms = new SqlParameter[]
                {
                    new SqlParameter("@fromtime ", SqlDbType.DateTime),
                    new SqlParameter("@totime ", SqlDbType.DateTime),
                    new SqlParameter("@selectcount ", SqlDbType.Int),

                };
                prms[0].Value = dtfromtime;
                prms[1].Value = dttotime;
                prms[2].Value = rank;
                SqlConnection con = SqlHelper.GetConnection();
                DataSet ds = SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "sp_titles", prms);
                DataTable dt = ds.Tables[0];
                return JsonConvert.SerializeObject(dt);
            }

 
        }

    }
}
